package com.hspedu.api;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/1
 * @time 19:08
 */
public class API_ {
    public static void main(String[] args) throws UnknownHostException {
        //获取本机的InetAddress对象
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println("localHost = " + localHost);

        //根据域名返回一个InetAddress对象
        InetAddress host1 = InetAddress.getByName("www.7blogs.top");
        System.out.println("host1 = " + host1);

        //根据指定主机名返回一个InetAddress对象
        InetAddress host2 = InetAddress.getByName("LAPTOP-4AKV837U");
        System.out.println("host2 = " + host2);

        //通过InetAddress对象，获取对应的地址
        String host1Address = host1.getHostAddress();
        System.out.println("host1Address = " + host1Address);

        //通过InetAddress获取主机名或域名
        String hostName = host1.getHostName();
        System.out.println("hostName = " + hostName);

    }
}
